package cn.stylefeng.guns.modular.controller;


import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.Order;
import cn.stylefeng.guns.modular.service.IOrderService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author XiangTianGe
 * @since 2020-04-14
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    private static String PREFIX = "/order/";

    @Autowired
    private IOrderService iOrderService;

    /**
     * 跳转订单首页
     */
    @RequestMapping
    public ModelAndView index() {
        ModelAndView index = iOrderService.index();
        index.setViewName(PREFIX + "order.html");
        return index;
    }

    @ResponseBody
    @RequestMapping("list")
    public LayuiPageInfo list(String keyword, Integer type, String timeLimit, Integer status, Long userId) {
        //获取分页参数
        Page<Order> page = LayuiPageFactory.defaultPage();

        //拼接查询条件
        String beginTime = null;
        String endTime = null;

        if (ToolUtil.isNotEmpty(timeLimit)) {
            String[] split = timeLimit.split(" - ");
            beginTime = split[0];
            endTime = split[1];
        }
        //根据条件查询日志
        return iOrderService.getList(page, keyword, beginTime, endTime, type, status,userId);
    }

}

